<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>setting config add</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/super_cmdb/css/font.css">
    <link rel="stylesheet" href="/static/super_cmdb/css/xadmin.css">

  </head>

  <body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form" >
          <div class="layui-form-item">
              <label for="config_content" class="layui-form-label" style="width: 100px">
                  <span class="x-red">*</span>config content
              </label>
              <div class="layui-input-inline">
                  <textarea type="text" id="config_content" name="config_content" style="width: 1200px; height: 600px;background-color: black;color: greenyellow;font-size: 15px;line-height: 20px">{{ config_content_obj.config_content }}</textarea>
              </div>
          </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label" style="padding-left: 35px;">
              </label>
              <button class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.cookie.js"></script>
    <script>
        $(function () {
            $.ajaxSetup({
                beforeSend:function (xhr,settings) {
                    xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken"));
                }
            })
        });
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 1){
                return '昵称至少得1个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
            {#$("#add").click(function (data) {#}
            {#    console.log(data);#}
            {#    if (data){#}
            {#        alert("添加成功", {icon: 6});#}
            {#    } else {#}
            {#        alert("添加失败", {icon: 6});#}
            {#    }#}
            //{#})#}
          form.on('submit(add)', function(data){
            //console.log(data);
            //发异步，把数据提交给django
              $.ajax({
                    url: "/k8s/setting_config_add/",
                    type: "POST",
                    //data: $('#layui-form').serialize(),
                    data: {
                        "config_content":$("#config_content").val()
                    },
                    success: function (data) {
                        //console.log(data);
                        layer.alert(data, {icon: 6});
                    }
                });
            console.log(data,function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
          });
        });
    </script>

  </body>

</html>
